2_MINIMUM_STARTING_BASE
=======================
Files
  updater_only_Ver3.bas   Every sub, function, constant and buffer of the updater, with the web-SERVER code removed: no WiFi start-up,
                          no WEB TCP INTERRUPT, no request-reading loop, no reconnect logic, no main loop. A PARTS LIST for another
                          web program. It is NOT a program that runs on its own.
  upload.html             The page that talks to it (same file as in 1_Working_Example).

STATUS: this file was cut out of the working program (1_Working_Example) and has never been run. A static check found no
missing routines and no undeclared names other than the two the host must provide. Treat it as a starting base, not as tested code.

What YOUR program must provide
  ConnData()   integer array (about 512 elements) holding the request just read with WEB TCP READ ... (a LongString)
  ConnNum      the connection number of that request (the replies use it for WEB TCP SEND / WEB TRANSMIT CODE / WEB TCP CLOSE)
  Your own web loop: interrupt sets a flag, main loop reads each connection and calls HandleRequest (or your own route table).
  In your MAIN LOOP add:     If SwitchAt > 0 Then If Timer > SwitchAt Then DoSwitch
      (INSTALL/ROLLBACK reply first, and the program is loaded here a moment later, after the connection has closed.)
  Serve upload.html:         SendFile PAGE_FILE$, "text/html"   (already inside HandleRequest)
  Call CodeChk at the top of your program, and keep the CodeChk sub at the very END of the file.
  Set PROG_VER$ to a new value for every release.

Routes (inside HandleRequest; copy them into your own route table if you have one)
  GET /up?...        DoUpload     one piece of a file
  GET /list          DoList       files, running version, whether a program / backup is waiting
  GET /get?f=NAME    DoGet        a web file back (the page uses it to verify an upload)
  GET /ver           (inline)     {"v":version,"msg":why the last install stopped}
  GET /install?go=1  DoInstall
  GET /rollback?go=1 DoRollback
  GET /cleanup?go=1  DoCleanup    deletes the uploaded copy once the new program is running
  GET / and /upload.html          the page
  Put your login / role / edit-lock checks IN FRONT of all of these. Updating should be for administrators only.

Order of the subs (what calls what)
  HandleRequest -> DoUpload -> ResetUpload, AdlerAdd, FlushBuf, FinishUpload
  DoInstall -> PrepInstall (tail check + backup via SAVE), CheckEncHeader (for .enc), FetchKey
  DoSwitch -> StageToBas (the .enc decrypt, only for encrypted installs), PrepInstall, then RUN
  Helpers: Reply, ReplyOk, ReplyErr, SendFile, QueryVal, PctDecode, Plus2Sp, Clean, GoodName, IsProgName, BytesOf, NewReady, ShowMsg, DebugMsg

If you do not want encrypted updates
  Delete CheckEncHeader, FetchKey, StageToBas, the CIn()/COut() arrays and the "NewKind = 1" branch in DoInstall / the
  Job = "enc" branch in DoSwitch. Everything else stands alone.

Things to keep when you merge
  - The updater code itself must stay in every program you ship, or the next update cannot come from the web.
  - The names: do not start a name with an MMBasic word (PIECE clashes with PI, LoadKey with LOAD ...). See ../1_Working_Example/README.txt
    and ../3_Encryption/ for the lessons.
  - 255-character limit on strings AND on program lines.
